package mil.af.amc.adpetracker.web.helpers;

import mil.af.amc.adpetracker.model.EquipmentItem;
import mil.af.amc.adpetracker.model.MaintenanceEntry;
import mil.af.amc.adpetracker.service.EquipmentItemService;
import mil.af.amc.adpetracker.service.MaintenanceService;
import mil.af.amc.radtaglibrary.tags.PageContextAwareBean;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.jsp.PageContext;
import java.util.List;

/**
 * Please fill in this javadoc
 *
 * @author TSgt Jason Ferguson
 */
@Service("maintenanceViewHelper")
public class MaintenanceViewHelper implements PageContextAwareBean {

    private PageContext pageContext;

    @Autowired
    public void setPageContext(PageContext pageContext) {
        this.pageContext = pageContext;
    }

    private MaintenanceService maintenanceService;

    @Autowired
    public void setMaintenanceService(MaintenanceService maintenanceService) {
        this.maintenanceService = maintenanceService;
    }

    private EquipmentItemService equipmentItemService;

    @Autowired
    public void setEquipmentItemService(EquipmentItemService equipmentItemService) {
        this.equipmentItemService = equipmentItemService;
    }

    public List<MaintenanceEntry> getItemEntries() {

        int itemId = Integer.parseInt(pageContext.getRequest().getParameter("itemId"));
        EquipmentItem item = equipmentItemService.getById(itemId);

        return item.getMaintenanceEntries();
    }
}
